package me.xhy.java.springboot3.r2dbc.s02r2dbctemplate;

import me.xhy.java.springboot3.r2dbc.s00application.S002Entity;
import me.xhy.java.springboot3.r2dbc.s00application.S001Application;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
import org.springframework.data.relational.core.query.Criteria;
import org.springframework.data.relational.core.query.Query;

import java.util.concurrent.TimeUnit;

@SpringBootTest(classes = S001Application.class)
public class S021R2dbcTemplate {

  @Autowired
  R2dbcEntityTemplate r2dbcEntityTemplate;

  @Test
  void test() throws Exception {

    //1、Criteria构造查询条件  where id=1 and name=张三
    Criteria criteria = Criteria
        .empty()
        .and("id").is(1801610513433604098L);

    //2、封装为 Query 对象
    Query query = Query.query(criteria);


    r2dbcEntityTemplate
        // 在实体类上使用 @Table("xs1_t_demo1") 指定表明
        .select(query, S002Entity.class)
        .subscribe(i -> System.out.println("S002Entity = " + i));

    TimeUnit.SECONDS.sleep(10);

  }
}
